//@see next js function is for init tree,add,edit,delete menuresource 9:46 2008-2-28

/**
* @todo：初始化菜单资源树
* @date：9:58 2008-2-28
* @author：hyh
*/
function pageInit(id){
	DWRUtil.useLoadingMessage("正在读取数据...");
	ConfigAction.getAclmenuresourceListToHtml(id,function(data){
		document.getElementById("category_tree").innerHTML = data;
		treeObj = new JSDragDropTree();
		treeObj.setImageFolder('../components/drag-drop-folder-tree/images/');
		treeObj.setTreeId('dhtml_tree');
		treeObj.setMaximumDepth(10);
		treeObj.setAddAllowed(true);
		treeObj.setEditAllowed(true);
		treeObj.setDeleteAllowed(true);
		treeObj.setUserFunctionAfterDropDragableNodes(function(id,pId){changeAclmenuresourceNode(id,pId)});
		treeObj.setMessageMaximumDepthReached('超过最多级别'); 
		treeObj.initTree();
		treeObj.expandAll();
	});
}

/**
* @todo：移动菜单资源树节点
* @date：9:46 2008-2-28
* @author：hyh
*/
function changeAclmenuresourceNode(id,pId){
	DWRUtil.useLoadingMessage("正在读取数据...");
	if(confirm("确定要移动此节点吗？")){
		ConfigAction.changeAclmenuresourceNode(id,pId);
	}else{		
		JSTreeObj.cancelDropDragableNodes();	
	}
}

/**
* @todo：添加菜单资源树节点
* @date：9:46 2008-2-28
* @author：hyh
*/
function addTreeNode(id,/*String*/title){
	menuresourceOpInit();
	DWRUtil.setValue("pname",title);
	DWRUtil.setValue("parentid",id);
}

/**
* @todo：编辑菜单资源树节点
* @date：9:47 2008-2-28
* @author：hyh
*/
function editTreeNode(id,pTitle){
	if(id != "0"){
		menuresourceOpInit(id);
		DWRUtil.setValue("pname",pTitle);
		setMenuresourceEditHtml();
	}else{
		setMenuresourcedetail("");
	}
}

/**
* @todo：菜单资源添加编辑详情初始化
* @date：9:47 2008-2-28
* @author：hyh
*/
function menuresourceOpInit(id){
	setMenuresourcedetail($("div_menuresource_op").innerHTML);
	if(id != null && id != ""){//for edit detail
		setMenuresourceDetailHtml();//detail
		getMenuresourceDetail(id);
	}
}

/**
* @todo：读取菜单资源详情
* @date：9:47 2008-2-28
* @author：hyh
*/
function getMenuresourceDetail(/*String*/id){
	DWRUtil.useLoadingMessage("正在读取数据...");
	ConfigAction.getAclmenuresource(id,function(oJSAclmenuresourceBean){
		setFormValue(oJSAclmenuresourceBean);
		$("url").value = oJSAclmenuresourceBean.url;
	});
}

/**
* @todo：菜单资源树保存（添加或编辑）
* @date：9:47 2008-2-28
* @author：hyh
*/
function saveMenuresource(){
	DWRUtil.useLoadingMessage("正在保存数据...");
	var oJSAclmenuresourceBean = new JSAclmenuresourceBean();
	getFormValue(oJSAclmenuresourceBean);
	if(oJSAclmenuresourceBean.menuname == ""){
		alert("名称不能为空！");
		$("menuname").focus();
		return false;
	}
	if(oJSAclmenuresourceBean.menutype == "0"){
		alert("请选择菜单类型！");
		$("menutype").focus();
		return false;
	}
	if(oJSAclmenuresourceBean.menuorder == ""){
		alert("菜单序号不能为空！");
		$("menuorder").focus();
		return false;
	}
	if(!/^[-]{0,1}[0-9]{1,}$/.test(oJSAclmenuresourceBean.menuorder)){
		alert("菜单序号必须为数字！");
		$("menuorder").focus();
		return false;
	}
	if(oJSAclmenuresourceBean.id == ""){//新增
		ConfigAction.insertAclmenuresource(oJSAclmenuresourceBean,function(data){
			alert("新增菜单资源成功");
			setMenuresourcedetail("");
			treeObj._addTreeNode(oJSAclmenuresourceBean.parentid,data.id,oJSAclmenuresourceBean.menuname);
		});
	}else{//编辑
		ConfigAction.updateAclmenuresource(oJSAclmenuresourceBean,function(data){
			alert(data);
			setMenuresourceDetailHtml();
			//不刷新整个树
			treeObj._editTreeNode(oJSAclmenuresourceBean.id,oJSAclmenuresourceBean.menuname);
		});
	}
	//showBeanValue(oJSAclmenuresourceBean);
}

/**
* @todo：删除菜单资源
* @date：9:47 2008-2-28
* @author：hyh
*/
function deleteTreeNode(id){
	DWRUtil.useLoadingMessage("正在删除组织数据...");
	ConfigAction.deleteAclmenuresource(id,function(data){
		alert(data);
		setMenuresourcedetail("");
		treeObj._deleteTreeNode(id);
	});
}

/**
* @todo：查看菜单资源树
* @date：9:48 2008-2-28
* @author：hyh
*/
function getDetail(id){
	if(id != "0"){
		var pTitle = $(id).parentNode.parentNode.getElementsByTagName("A")[0].innerHTML;
		menuresourceOpInit(id);
		DWRUtil.setValue("pname",pTitle);
	}else{
		setMenuresourcedetail("");
	}
}

//@see next js function is for menuresource common function 9:44 2008-2-28

/**Aclmenuresourcr Object 9:44 2008-2-28*/
function JSAclmenuresourceBean(){
	this.menuname = "";
	this.remark = "";
	this.parentid = "";
	this.id = "";
	this.url = "";
	this.menuorder = "";
	this.menutype = "";
	this.imagepath = "";
}

/**set menuresource detail div 9:45 2008-2-28*/
function setMenuresourcedetail(str){
	$("div_menue_detail").innerHTML = str;
}

/**展示详情页面 9:45 2008-2-28*/
function setMenuresourceDetailHtml(){
	$("menuop_title").innerHTML = "<img src=\"../themes/default/images/Contacts.gif\" width=\"16\" height=\"16\">菜单资源信息";
	$("op_button").innerHTML = $("div_hidden_detail").innerHTML;
	setInputReadOnly("menuname");
	setInputReadOnly("menutype");
	setInputReadOnly("url");
	setInputReadOnly("imagepath");
	setInputReadOnly("menuorder");
	setInputReadOnly("remark");
}

/**展示编辑页面 9:45 2008-2-28*/
function setMenuresourceEditHtml(){
	$("menuop_title").innerHTML = "<img src=\"../themes/default/images/Contacts.gif\" width=\"16\" height=\"16\">编辑菜单资源";
	$("op_button").innerHTML = $("div_hidden_edit").innerHTML;
	setInputReadOnly("menuname","false");
	setInputReadOnly("menutype","false");
	setInputReadOnly("url","false");
	setInputReadOnly("imagepath","false");
	setInputReadOnly("menuorder","false");
	setInputReadOnly("remark","false");
}